import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:star_unbounded/model/global_theme.dart';
import 'package:star_unbounded/router/NotPage404.dart';
import "package:star_unbounded/router/index.dart";
import "package:star_unbounded/model/clipboard_data.dart";
import 'package:star_unbounded/router/login.dart';
import 'package:star_unbounded/utils/icons.dart';
void main() {

  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});
  @override
  State<StatefulWidget> createState() => _MainApp();
}

class _MainApp extends State<MainApp> {
  @override
  Widget build(BuildContext context) {


    return MultiProvider(
        providers: [
          ChangeNotifierProvider<GlobalTheme>(create: (_)=>GlobalTheme()),
          ChangeNotifierProvider<ClipboardData>(create: (_)=>ClipboardData()),
        ],

        builder: (content,widget) {
          bool useLightTheme = content.select((GlobalTheme g) => g.useLightTheme);
          Color colorSchemeSeed = content.select((GlobalTheme g) =>  g.colorSchemeSeed.color);
          return MaterialApp(
            debugShowCheckedModeBanner: false,
            themeMode: ThemeMode.dark,
            theme: ThemeData(
              useMaterial3: true,
              brightness: useLightTheme ? Brightness.light : Brightness.dark,
              colorSchemeSeed: colorSchemeSeed,
            ),
            // home:  IndexRouter(context: content),
            initialRoute: "/login",
            routes: {
              "/":(_)=>const IndexRouter(),
              "/login":(_)=>const LoginRouter(),
              "/404":(_)=>const NotPage404Router()
            },
            onGenerateRoute: (RouteSettings settings){
              debugPrint(settings.name);
               switch(settings.name){
                 case "/":
                 case "/login":
                   break;
                 default:
                   return MaterialPageRoute(builder: (_)=>const NotPage404Router());
               }

            },
          );
        }
    );
  }
}